import { Component, OnInit } from '@angular/core';
import { Router } from "@angular/router";
import { WebsocketService } from '../../../services/websocket.service';
import { ScannerComponent } from './scanner/scanner.component'
import { ActivatedRoute, Params } from '@angular/router';
import { commService } from "../../../services/comm.service";
import { BaseUiService } from '../../../services/base-ui.service';
import { LoginInfoService } from '../../.././services/login-info.service';
import { HttpService } from '../../../services/http.service';

@Component({
  selector: 'app-uploading',
  templateUrl: './uploading.page.html',
  styleUrls: ['./uploading.page.scss'],
})
export class UploadingPage implements OnInit {

  private imgSrc='';
  constructor(public router:Router,
    public HttpService: HttpService,
    public activeRoute: ActivatedRoute,
    public websocket: WebsocketService,
    public commService: commService,
    public BaseUiService: BaseUiService,
    public LoginInfoService: LoginInfoService,) { }
  ngOnInit() {
    let userInfo = this.LoginInfoService.getlocal("user")
    let urlId = this.HttpService.websockurl() + userInfo.idCard
    this.websocket.createObservableScoket(urlId)
    this.websocket.getMessage().subscribe((res)=>{
       console.log(res);
    })
    this.activeRoute.queryParams.subscribe((params: Params) => {
      console.log(params)
      if(params.object=="200"){
          this.websocket.sendMessage({
          userId:"appcode",
          fromUserId:"",
          code:"1200",
          data:window.localStorage.getItem("userInfo")
        })
      }
    });
  }

  ionViewDidEnter(){}
  scannner(){
    
    this.commService.QRCode().subscribe(
      res=>{
        console.log(res)
        if( res.trim() == "nanjingshichenggongzheng123698745666"){
          this.BaseUiService.showToast('验证成功','success','top');
          this.websocket.sendMessage({
            userId:"321324199307024618",
            fromUserId: this.LoginInfoService.getlocal('user').idCard,
            code:"1200",
            data:window.localStorage.getItem("userInfo")
          })
        }else if(res.trim() == '123698745666nanjingshichenggongzheng'){
          this.BaseUiService.showToast('验证成功','success','top');
          this.router.navigate(['/mycenter/uploadImg'])
          
        }else{
          console.log(res.trim()== "nanjingshichenggongzheng123698745666")
          this.BaseUiService.showToast('验证失败','warning','top');
        }
      }
    )
  }
   
    // async  scannner(){
    //   this.websocket.initializeWebSocket();
    //   let modal = await this.modalController.create({
    //     component: ScannerComponent,
    //     mode: "md",
    //     cssClass: "conditions",
    //     componentProps: {
    //       // "imgs": this.imgs,
    //       // "flag": false
    //     },
      
    //   });
    //   modal.present();
     
      //模态框被关闭后回回调该方法 res 为返回值
      // modal.onDidDismiss().then(res => {
      //   if(res.data.qrInfo=="200"){
           
      //   }
      // })
  // }
}
